package dnl.jexem.camouflaj;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class Config {

	private Properties properties;

	public Config(File propertiesFile) throws IOException {
		this.properties = new Properties();
		properties.load(new FileReader(propertiesFile));
	}

	public RemoteCommandManager getRemoteCommandManager() throws IOException {
		String connectivity = (String) properties.get("connectivity");
		if (!"ftp".equalsIgnoreCase(connectivity)) {
			throw new UnsupportedOperationException(
					"Currently only FTP connectivity is supported.");
		}
		String host = (String) properties.get("host");
		String user = (String) properties.get("user");
		String pass = (String) properties.get("pass");
		pass = Crypter.decrypt(pass);
		String workDir = (String) properties.get("workDir");
		RemoteCommandManager commandManager = new FtpCommandManager(host, user, pass, workDir);
		commandManager.setEncryptCommands(encryptCommands());
		return commandManager;
	}
	
	public boolean encryptCommands(){
		String enc = (String) properties.get("encrypt.command");
		return "true".equalsIgnoreCase(enc);
	}
}
